package com.walleipt.corgi.api.chain;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class DefaultContext implements Context
{
	Map<Object, Object> attributes = new HashMap<Object, Object>() ;
	
	@Override
	public boolean containsAttribute(Object key)
	{
		return attributes.containsKey(key);
	}

	@Override
	public Object getAttribute(Object key, Object defaultValue)
	{
		Object value = attributes.get(key) ;
		return value==null?defaultValue:value ;
	}

	@Override
	public Object getAttribute(Object key)
	{
		return attributes.get(key) ;
	}

	@Override
	public Set<Object> getAttributeKeys()
	{
		return Collections.unmodifiableSet(attributes.keySet()) ;
	}

	@Override
	public Object removeAttribute(Object key)
	{
		return attributes.remove(key) ;
	}

	@Override
	public void setAttribute(Object key, Object value)
	{
		attributes.put(key, value) ;
	}

	@Override
	public void setAttributes(Map<Object, Object> attributes)
	{
		attributes.putAll( attributes ) ;
	}
	
}
